<template>
    <LmsDialog v-model="modelValue" title="生成代码参数配置" @ok="ok" :close-on-click-modal="false" >
        <el-form label-width="10rem">
            <el-row>
                <el-col :span="24">
                    <el-form-item label="实体类包路径" prop="entityPath">
                        <el-input v-model="form.entityPath" placeholder="格式：路径.路径.路径(最终路径)" clearable />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label="Mapper包路径" prop="mapperPath">
                        <el-input v-model="form.mapperPath" placeholder="格式：路径.路径.路径(最终路径)" clearable />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label="service包路径" prop="servicePath">
                        <el-input v-model="form.servicePath" placeholder="格式：路径.路径.路径(最后带service即可，不需要带impl)" clearable />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label="controller包路径" prop="controllerPath">
                        <el-input v-model="form.controllerPath" placeholder="格式：路径.路径.路径(最终路径)" clearable />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col>
                    <el-form-item label="是否包含导出逻辑" prop="containExport">
                        <el-radio-group v-model="form.containExport" class="ml-4">
                            <el-radio :label="true">包含</el-radio>
                            <el-radio :label="false">不包含</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
    </LmsDialog>
</template>
<script setup lang="ts">
import { ref } from 'vue'
import api from '@/api/gen/index'
import { FileUtil } from '@/utils/FileUtil';
import { ElMessageBox } from 'element-plus'

const modelValue = defineModel()

const props = defineProps<{
    tableList: any[]
}>()

const form = ref<any>({
    containExport: false
})

const ok = async () => {
    console.log(form.value)
    const params = { ...form.value, tableList: props.tableList }
    const res = await api.createCode(params)
    FileUtil.download(res)
    ElMessageBox.confirm(params.tip, '生成成功，是否关闭弹窗？', {
        confirmButtonText: '是',
        cancelButtonText: '否',
        type: 'warning',
        draggable: true
    }).then(() => {
        modelValue.value = false
    })
    
}

</script>